<template>
	<view class="content">
		<view class="form">
			<view class="titel">
				添加工序
			</view>
			<view class="itembox" @click="brandBnt()">
				<view class="bnt">
					选择工序 </view>

			</view>
			<view class="itembox" v-if="info.name">
				<view class="name">
					工序名称:
				</view>
				<view class="inputBox">
					<input type="number" v-model="info.name" placeholder="请填写工序名称" />
				</view>
			</view>
			<view class="itembox" v-if="info.code">
				<view class="name">
					工序编码:
				</view>
				<view class="inputBox">
					<input type="number" disabled="" v-model="info.code" placeholder="请填写工序编码" />
				</view>
			</view>
			<view class="itembox" v-if="info.goodsName">
				<view class="name">
					产品名称:
				</view>
				<view class="inputBox">
					<input type="number" v-model="info.goodsName" placeholder="请填写产品名称" />
				</view>
			</view>
			<view class="itembox" v-if="info.goodsModel">
				<view class="name">
					产品型号:
				</view>
				<view class="inputBox">
					<input type="number" v-model="info.goodsModel" placeholder="请填写产品型号" />
				</view>
			</view>
			<view class="itembox" v-if="info.gongxuName">
				<view class="name">
					生产产品名称:
				</view>
				<view class="inputBox">
					<input type="number" v-model="info.gongxuName" placeholder="请填写生产产品名称" />
				</view>
			</view>
			<view class="itembox" v-if="info.gongxuModel">
				<view class="name">
					生产产品型号:
				</view>
				<view class="inputBox">
					<input type="number" v-model="info.gongxuModel" placeholder="请填写生产产品型号" />
				</view>
			</view>
			<view class="itembox" v-if="info.shuoming">
				<view class="name">
					产品说明:
				</view>
				<view class="inputBox">
					<input type="text" v-model="info.shuoming" placeholder="请输入产品说明" />
				</view>
			</view>
			<view class="itembox" v-if="info.photo">
				<view class="name">
					关联设备:
				</view>
				<view class="inputBox">
					<input type="text" v-model="info.photo" placeholder="请输入关联设备" />
				</view>
			</view>
			<view class="itembox" v-if="info.remark">
				<view class="name">
					备注:
				</view>
				<view class="inputBox">
					<input type="text" v-model="info.remark" placeholder="请输入备注" />
				</view>
			</view>
		</view>
		<view class="bottom-box">
			<view class="bnt" @click="addBnt()">
				确定
			</view>
		</view>
		<brand-popup ref="brandPopup" @brandBnt="brandSelect($event)"></brand-popup>
	</view>
</template>

<script>
	import * as index from '@/api/index.js'
	export default {
		data() {
			return {
				info: {},
				count: '',
				form: {},
				id: '',
				goodsCount: '',
			};
		},
		onLoad(e) {
			this.id = e.id
			this.count = e.count
			this.goodsCount = e.goodsCount
			this.dictType()
		},
		methods: {
			dictType() {
				index.typesBatch({
					'sys_user': 'sys_user',
				}).then(res => {
					this.workerList = res.data.sys_user
				})
			},
			// 打开品牌弹窗
			brandBnt() {
				this.$refs.brandPopup.open()
			},
			// 选择品牌
			brandSelect(e) {
				this.info = e
			},
			jianting() {
				var pages = getCurrentPages();
				console.log(pages.length);
				var Page = pages[pages.length - 1]; //当前页
				console.log(pages[pages.length - 1].route); //输出当前路由
				var prevPage = pages[pages.length - 2];
				console.log(pages[pages.length - 2].route); //输出上一个页面的路由
				if (pages[pages.length - 2].route ==
					'pagesA/orderAdmin/productionOrder/productionDetails/allocation/index') { //确定要返回到相应页面，在触发
					prevPage.$vm.reload()
				}
			},
			addBnt(e) {
				if (!this.info.code) {
					this.$modal.msgError("请选择工序");
					return;
				}
				uni.showModal({
					title: '提示',
					content: '确定新增吗？',
					success: (res) => {
						if (res.confirm) {
							var data = {
								ids: [],
								saleId: this.id,
								goodsCount: this.count
							}
							data.ids[0] = this.info.id
							index.addGoodsDoGongxu(data).then(res => {
								setTimeout(() => {
									uni.navigateBack(-1);
									this.jianting();
								}, 100);
							});
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
		}

	}
</script>

<style lang="scss">
	.content {
		padding-left: 20rpx;
		padding-right: 20rpx;
		padding-bottom: 250rpx;

		.bnt {
			color: #ffffff;
			width: 206rpx;
			height: 68rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			border-radius: 10rpx;
			background: #4D8987;
		}

		.form {
			margin-top: 20rpx;
			padding: 20rpx;
			background-color: #ffffff;
			border-radius: 10rpx;

			.titel {
				padding-top: 30rpx;
				padding-bottom: 30rpx;
				color: #333;
				font-size: 28rpx;
				font-weight: bold;
			}

			.itembox {
				border-top: 1px solid #EDEDED;
				display: flex;
				align-items: center;
				padding-top: 30rpx;
				padding-bottom: 30rpx;

				.name {
					text-align: right;
					width: 160rpx;
					color: #999;
					font-size: 28rpx;
				}

				.inputBox {
					padding-left: 20rpx;
					width: 600rpx;
					color: #333;
					font-size: 28rpx;
				}
			}
		}

		.bottom-box {
			position: fixed;
			bottom: 0;
			left: 0;
			width: 750rpx;
			padding: 30rpx;
			padding-bottom: 120rpx;
			height: 120rpx;
			background: #ffffff;
			display: flex;
			justify-content: center;

			.bnt {
				color: #ffffff;
				width: 306rpx;
				height: 88rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				border-radius: 10rpx;
				background: #4D8987;
			}
		}
	}

	.add-worker-btn {
		margin-top: 20rpx;
		padding: 20rpx;
		background-color: #f0f0f0;
		border-radius: 10rpx;
		text-align: center;
		color: #333;
		font-size: 28rpx;
	}
</style>